package com.wyb.service.impl;

import com.wyb.mapper.UserMapper;
import com.wyb.mapper.UserRoleMapper;
import com.wyb.pojo.User;
import com.wyb.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;



@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private UserRoleMapper userRoleMapper;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private UserMapper userMapper;

    public boolean register(User user){

        user.setPassword(passwordEncoder.encode(user.getPassword()));

        int insert = userMapper.insert(user);
        int i = 0;
        if(user.getId()!=0||user.getId()!=null){
            i = userRoleMapper.insertId(user.getId());
        }

        return insert == 0 || i == 0 ? false: true;

    }

    @Override
    public boolean findUserName(String userName) {
        return userMapper.selectByUserName(userName) == 0 ? true:false;
    }

}
